<template>
  <div class="employee-container">
    <!-- 搜索区域 -->
    <div class="search-container">
      <div class="search-label">员工姓名：</div>
      <el-input
        v-model="params.name"
        clearable
        placeholder="请输入内容"
        class="search-main"
        @clear="clearSearch"
      />
      <el-button type="primary" @click="doSearch">查询</el-button>
    </div>
    <div class="create-container">
      <el-button type="primary" @click="openForm">添加员工</el-button>
    </div>
    <!-- 表格区域 -->
    <div class="table">
      <el-table style="width: 100%" :data="employeeList">
        <el-table-column type="index" label="序号" />
        <el-table-column label="员工姓名" width="180" prop="name" />
        <el-table-column label="登录账号" width="180" prop="userName" />
        <el-table-column label="联系方式" width="120" prop="phonenumber" />
        <el-table-column label="角色" width="120" prop="roleName" />
        <el-table-column label="状态">
          <template #default="scope">
            {{ scope.row.status === 0? "未启用" :'启用' }}
          </template>
        </el-table-column>
        <el-table-column label="添加时间" prop="createTime" />
        <el-table-column label="操作" fixed="right" width="120">
          <template #default="scope">
            <el-button
              size="mini"
              type="text"
              @click="editUserList(scope.row.id)"
            >编辑</el-button>
            <el-button
              size="mini"
              type="text"
              @click="delUserList(scope.row.id)"
            >删除</el-button>
            <el-button size="mini" type="text">重置密码</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-container">
      <el-pagination
        layout="total, prev, pager, next"
        :total="total"
        :page-size="params.pageSize"
        @current-change="pageChange"
      />
    </div>
  </div>
</template>
<script >
import {
  employeeListAPI,
  getPoleListAPI,
  addUserListAPI,
  delUserListAPI,
  editUserListAPI,
  userDetailListAPI
} from '@/api/employee'
export default {
  name: 'Employee',
  data() {
    return {
      //! 分页
      params: {
        name: '',
        page: 1,
        pageSize: 5
      },
      employeeList: [] //! 默认渲染
    }
  },
  methods: {
  //! 渲染
    async renderEmployeeList() {
      const res = await employeeListAPI(this.params)
      // console.log(res);
      this.employeeList = [...res.data.rows]
      this.total = res.data.total
    },
    //! 搜索
    doSearch() {
      this.renderEmployeeList()
    },
    //! 页码条数发生改变
    pageChange(val) {
      console.log(val)
      this.params.page = val
      this.renderEmployeeList()
    },
    //! 清空输入框
    clearSearch() {
      this.params.page = 1
      this.renderEmployeeList()
    },
  }
}
</script>

<style lang="scss" scoped>
.employee-container {
  padding: 10px;
}

.search-container {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgb(237, 237, 237, 0.9);
  padding-bottom: 20px;

  .search-label {
    width: 100px;
  }

  .search-main {
    width: 220px;
    margin-right: 10px;
  }
}
.create-container {
  margin: 10px 0px;
}
.page-container {
  padding: 4px 0px;
  text-align: right;
}
.form-container {
  padding: 0px 80px;
}
</style>
